import requests

from api.ihrm_longin_aip import Ihrm_LonginAPI

class Ihrm_amendAPI:
    @classmethod
    def ihrm_amend(cls, url_amend_body,id):
        # 准备ihrm登录请求的请求体，获取到令牌
        url_longin_body = {"mobile": "13800000002", "password": "123456"}

        # 调用ihrm登录接口层的登录请求类的方法，参数中传递请全体，获取响应数据
        res = Ihrm_LonginAPI.ihrm_longin(url_longin_body)

        # 从响应数据中获取到的结果，拼成一个完整的令牌
        token = "Bearer " + res.json()["data"]

        # 修改员工
        url_amend_hang = f"http://ihrm-test.itheima.net/api/sys/user/{id}"
        url_amend_head = {"Authorization": token}
        res_amend = requests.put(url=url_amend_hang, headers=url_amend_head, json=url_amend_body)
        print("修改员工结果===", res_amend)

        return res_amend
